package io.itit.ecp.admin.provide.helper.datarangelevel;

import io.itit.ecp.admin.common.enums.IDataRangeEnums.RangeLevel;
import io.itit.ecp.admin.server.entity.SceneRoomEntity;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.schema.Table;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 数据范围 按项目
 */
@Component
public class DataRangeLevelProjectHelper extends AbsDataRangeLevelHelper {

    @Override
    public RangeLevel rangeLevel() {
        return RangeLevel.rangeLevelProject;
    }

    @Override
    public List<SceneRoomEntity> listByScene(Collection<String> sceneIds) {
        return listByProject(sceneIds);
    }

    @Override
    public void processDataRange(List<SceneRoomEntity> roomList) {
        String userId = getUserId();
        putRangeLevelProject(userId, roomList);
        putRangeLevelCompany(userId, roomList);
    }

    @Override
    public Expression getSqlSegment(Table table, Map<String, List<String>> tableMap) {
        return buildProjectExpression(getUserId(), table, tableMap.get(table.getName()));
    }

}
